<template>
  <div class="container-content">
    <el-form
      ref="elForm"
      :model="formData"
      :rules="rules"
      size="medium"
      label-width="100px"
    >
      <el-form-item label-width="200px" label="银行名称" prop="accountName">
        <el-input
          v-model="formData.title"
          placeholder="请输入银行名称"
          clearable
          :style="{ width: '100%' }"
        >
        </el-input>
      </el-form-item>
      <el-form-item label-width="200px" label="银行地址" prop="bankAddress">
        <el-input
          v-model="formData.bankAddress"
          placeholder="请输入银行地址"
          clearable
          :style="{ width: '100%' }"
        >
        </el-input>
      </el-form-item>
      <el-form-item label-width="200px" label="描述" prop="bankDesc">
        <el-input
          v-model="formData.bankDesc"
          placeholder="请输入描述"
          clearable
          type="textarea"
          :style="{ width: '100%' }"
        >
        </el-input>
      </el-form-item>
      <!-- <el-form-item
                label-width="200px"
                label="银行网点"
                prop="bankAddress"
            >
                <el-input
                    v-model="formData.bankAddress"
                    placeholder="请输入银行地址"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item> -->
      <!-- <el-form-item
                label-width="200px"
                label="地区码"
                prop="bankAddress"
            >
                <el-input
                    v-model="formData.bankAddress"
                    placeholder="请输入银行地址"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item> -->
      <!-- <el-form-item
                label-width="200px"
                label="银行"
                prop="bankAddress"
            >
                <el-input
                    v-model="formData.bankAddress"
                    placeholder="请输入银行地址"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item> -->
      <!-- <el-form-item
                label-width="200px"
                label="地区名"
                prop="bankAddress"
            >
                <el-input
                    v-model="formData.bankAddress"
                    placeholder="请输入银行地址"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item> -->
      <el-form-item label-width="200px" label="联行号">
        <el-input
          v-model="formData.bankNo"
          placeholder="请输入银行地址"
          clearable
          :style="{ width: '100%' }"
        >
        </el-input>
      </el-form-item>
      <el-form-item label-width="200px" label="国别">
        <el-input
          v-model="formData.countryName"
          placeholder="请输入国别"
          clearable
          :style="{ width: '100%' }"
        >
        </el-input>
      </el-form-item>
      <el-form-item label-width="200px" label="省">
        <el-input
          v-model="formData.provinceName"
          placeholder="请输入省"
          clearable
          :style="{ width: '100%' }"
          @focus="openList('省')"
        >
        </el-input>
      </el-form-item>
      <el-form-item label-width="200px" label="市">
        <el-input
          v-model="formData.cityName"
          placeholder="请输入市"
          clearable
          :style="{ width: '100%' }"
          @focus="openList('市')"
        >
        </el-input>
      </el-form-item>
      <el-form-item label-width="200px" label="区">
        <el-input
          v-model="formData.countyName"
          placeholder="请输入区"
          clearable
          :style="{ width: '100%' }"
          @focus="openList('区')"
        >
        </el-input>
      </el-form-item>
    </el-form>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      :append-to-body="list"
      width="60%"
    >
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '国家'">
        <el-table-column property="wareName" label="名称"></el-table-column>
        <el-table-column property="wareCode" label="编码"></el-table-column>
        <el-table-column property="userId" label="创建人"></el-table-column>
        <el-table-column
          property="wareManagement"
          label="仓管id"
        ></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '省'">
        <el-table-column property="areaName" label="名称"></el-table-column>
        <el-table-column property="id" label="编码"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '市'">
        <el-table-column property="areaName" label="名称"></el-table-column>
        <el-table-column property="id" label="编码"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '区'">
        <el-table-column property="id" label="编码"></el-table-column>
        <el-table-column property="areaName" label="名称"></el-table-column>
      </el-table>
      <!-- <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        class="table-pagination"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :page-size="pageSize"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40, 50, 100]"
      >
      </el-pagination> -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { add } from "@/api/base/data";
import {
  updataKingBaseBankList,
  editKingBaseBankList,
  getAreaList,
} from "@/api/bim/outher";
export default {
  components: {},
  props: ["id"],
  data() {
    return {
      gridData: [],
      list: true,
      title: "",
      dialogVisible: false,
      flag: false,
      flag: false,
      formData: {
        title: "",
        bankAddress: "",
        bankDesc: "",
        countryId: "20230705392153575054249984",
        countryName: "中国",
      },
      rules: {
        title: [
          {
            required: true,
            message: "请输入银行名称",
            trigger: "blur",
          },
        ],
        bankAddress: [
          {
            required: true,
            message: "请输入银行地址",
            trigger: "blur",
          },
        ],
        bankDesc: [
          {
            required: true,
            message: "请输入描述",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    if (this.id != "") {
      updataKingBaseBankList(this.id).then((res) => {
        this.formData = res.data;
        this.formData.countryId="20230705392153575054249984",
        this.formData.countryName="中国",        
        this.flag = true;
      });
    }
  },
  methods: {
    // 点击打开弹窗
    openList(val) {
      this.title = val;
      this.dialogVisible = true;
      console.log(val);

      if (val == "省") {
        getAreaList({
          parentId: "20230705392153575054249984",
        }).then((res) => {
          this.gridData = res.rows;
        });
      } else if (val == "市") {
        getAreaList({ parentId: this.formData.provinceId }).then((res) => {
          this.gridData = res.rows;
        });
      } else if (val == "区") {
        getAreaList({ parentId: this.formData.cityId }).then((res) => {
          this.gridData = res.rows;
        });
      }
    },
    // 点击表格
    getRow(row) {
      this.dialogVisible = false;
      if (this.title == "省") {
        this.formData.provinceId = row.id;
        this.formData.provinceName = row.areaName;
      } else if (this.title == "市") {
        this.formData.cityId = row.id;
        this.formData.cityName = row.areaName;
      } else if (this.title == "区") {
        this.formData.countyId = row.id;
        this.formData.countyName = row.areaName;
      }
    },
    submitForm(cb) {
      if (this.flag) {
        this.$refs["elForm"].validate((valid) => {
          if (!valid) return;
          // TODO 提交表单
          editKingBaseBankList(this.formData, "KingBaseBank").then((res) => {
            if (res.code === 200) {
              cb();
              this.$message.success("修改成功");
              this.flag = false;
            }
          });
        });
      } else {
        this.$refs["elForm"].validate((valid) => {
          if (!valid) return;
          // TODO 提交表单
          add(this.formData, "KingBaseBank").then((res) => {
            if (res.code === 200) {
              cb();
              this.$message.success("新增成功");
            }
          });
        });
      }
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
    },
  },
};
</script>
<style>
.divider {
  margin: 0;
}
.el-icon-search {
  margin-top: 70% !important;
}</style>
